﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ClientBusinessMapping.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the ClientBusinessMapping type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Mapping
{
    using System.Diagnostics;

    using AutoMapper;

    using Hisaab.Client.Model;

    /// <summary>
    /// Defines the <seealso cref="ClientBusinessMapping"/> type.
    /// </summary>
    public class ClientBusinessMapping : Profile
    {
        /// <summary>
        /// Configures this instance.
        /// </summary>
        [DebuggerStepThrough]
        protected override void Configure()
        {
            CreateMap<Business.Entities.Account, Account>()
                .ForMember(s => s.AccountId, o => o.MapFrom(d => d.AccountId))
                .ForMember(s => s.AccountType, o => o.MapFrom(d => d.AccountType))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.AccountNumber, o => o.MapFrom(d => d.AccountNumber))
                .ForMember(s => s.Dirty, o => o.Ignore());

            CreateMap<Account, Business.Entities.Account>()
                .ForMember(s => s.AccountId, o => o.MapFrom(d => d.AccountId))
                .ForMember(s => s.AccountType, o => o.MapFrom(d => d.AccountType))
                .ForMember(s => s.AccountNumber, o => o.MapFrom(d => d.AccountNumber))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name));

            CreateMap<Business.Entities.AccountSummary, AccountSummary>()
                .ForMember(s => s.EndingBalance, o => o.MapFrom(d => d.EndingBalance))
                .ForMember(s => s.TransactionCount, o => o.MapFrom(d => d.TransactionCount))
                .ForMember(s => s.ChartData, o => o.MapFrom(d => d.ChartData))
                .ForMember(s => s.Dirty, o => o.Ignore());

            CreateMap<AccountSummary, Business.Entities.AccountSummary>()
                .ForMember(s => s.EndingBalance, o => o.MapFrom(d => d.EndingBalance))
                .ForMember(s => s.TransactionCount, o => o.MapFrom(d => d.TransactionCount))
                .ForMember(s => s.ChartData, o => o.MapFrom(d => d.ChartData));

            CreateMap<Business.Entities.AccountType, AccountType>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.Dirty, o => o.Ignore());

            CreateMap<AccountType, Business.Entities.AccountType>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name));

            CreateMap<Business.Entities.Tag, Tag>()
                .ForMember(s => s.TagId, o => o.MapFrom(d => d.TagId))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.Dirty, o => o.Ignore());

            CreateMap<Tag, Business.Entities.Tag>()
                .ForMember(s => s.TagId, o => o.MapFrom(d => d.TagId))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name));

            CreateMap<Business.Entities.Transaction, Transaction>()
                .ForMember(s => s.TransactionId, o => o.MapFrom(d => d.TransactionId))
                .ForMember(s => s.Title, o => o.MapFrom(d => d.Title))
                .ForMember(s => s.Details, o => o.MapFrom(d => d.Details))
                .ForMember(s => s.Amount, o => o.MapFrom(d => d.Amount))
                .ForMember(s => s.Account, o => o.MapFrom(d => d.Account))
                .ForMember(s => s.Date, o => o.MapFrom(d => d.Date))
                .ForMember(s => s.Tags, o => o.MapFrom(d => d.Tags))
                .ForMember(s => s.LinkedTransactionAccount, o => o.MapFrom(d => d.LinkedTransactionAccount))
                .ForMember(s => s.LinkedTransactionDate, o => o.MapFrom(d => d.LinkedTransactionDate))
                .ForMember(s => s.IsTransferTransaction, o => o.Ignore())
                .ForMember(s => s.RelatedTransactionId, o => o.MapFrom(d => d.RelatedTransactionId))
                .ForMember(s => s.TransactionType, o => o.MapFrom(d => d.TransactionType))
                .ForMember(s => s.Dirty, o => o.Ignore());

            CreateMap<Transaction, Business.Entities.Transaction>()
                .ForMember(s => s.TransactionId, o => o.MapFrom(d => d.TransactionId))
                .ForMember(s => s.Title, o => o.MapFrom(d => d.Title))
                .ForMember(s => s.Details, o => o.MapFrom(d => d.Details))
                .ForMember(s => s.Amount, o => o.MapFrom(d => d.Amount))
                .ForMember(s => s.Account, o => o.MapFrom(d => d.Account))
                .ForMember(s => s.Date, o => o.MapFrom(d => d.Date))
                .ForMember(s => s.Tags, o => o.MapFrom(d => d.Tags))
                .ForMember(s => s.LinkedTransactionAccount, o => o.MapFrom(d => d.LinkedTransactionAccount))
                .ForMember(s => s.LinkedTransactionDate, o => o.MapFrom(d => d.LinkedTransactionDate))
                .ForMember(s => s.RelatedTransactionId, o => o.MapFrom(d => d.RelatedTransactionId))
                .ForMember(s => s.TransactionType, o => o.MapFrom(d => d.TransactionType));

            CreateMap<Business.Entities.Transaction, ImportTransaction>()
               .ForMember(s => s.TransactionId, o => o.MapFrom(d => d.TransactionId))
               .ForMember(s => s.Title, o => o.MapFrom(d => d.Title))
               .ForMember(s => s.Details, o => o.MapFrom(d => d.Details))
               .ForMember(s => s.Amount, o => o.MapFrom(d => d.Amount))
               .ForMember(s => s.Account, o => o.MapFrom(d => d.Account))
               .ForMember(s => s.Date, o => o.MapFrom(d => d.Date))
               .ForMember(s => s.Tags, o => o.MapFrom(d => d.Tags))
               .ForMember(s => s.LinkedTransactionAccount, o => o.MapFrom(d => d.LinkedTransactionAccount))
               .ForMember(s => s.LinkedTransactionDate, o => o.MapFrom(d => d.LinkedTransactionDate))
               .ForMember(s => s.IsTransferTransaction, o => o.Ignore())
               .ForMember(s => s.RelatedTransactionId, o => o.MapFrom(d => d.RelatedTransactionId))
               .ForMember(s => s.TransactionType, o => o.MapFrom(d => d.TransactionType))
               .ForMember(s => s.Selected, o => o.UseValue(false))
               .ForMember(s => s.Dirty, o => o.Ignore());

            CreateMap<ImportTransaction, Business.Entities.Transaction>()
                .ForMember(s => s.TransactionId, o => o.MapFrom(d => d.TransactionId))
                .ForMember(s => s.Title, o => o.MapFrom(d => d.Title))
                .ForMember(s => s.Details, o => o.MapFrom(d => d.Details))
                .ForMember(s => s.Amount, o => o.MapFrom(d => d.Amount))
                .ForMember(s => s.Account, o => o.MapFrom(d => d.Account))
                .ForMember(s => s.Date, o => o.MapFrom(d => d.Date))
                .ForMember(s => s.Tags, o => o.MapFrom(d => d.Tags))
                .ForMember(s => s.LinkedTransactionAccount, o => o.MapFrom(d => d.LinkedTransactionAccount))
                .ForMember(s => s.LinkedTransactionDate, o => o.MapFrom(d => d.LinkedTransactionDate))
                .ForMember(s => s.RelatedTransactionId, o => o.MapFrom(d => d.RelatedTransactionId))
                .ForMember(s => s.TransactionType, o => o.MapFrom(d => d.TransactionType));

            CreateMap<Business.Entities.Vehicle, Vehicle>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.UserId, o => o.MapFrom(d => d.UserId))
                .ForMember(s => s.Dirty, o => o.Ignore());

            CreateMap<Vehicle, Business.Entities.Vehicle>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.UserId, o => o.MapFrom(d => d.UserId));

            CreateMap<Business.Entities.VehicleTransaction, VehicleTransaction>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.TransactionId, o => o.MapFrom(d => d.TransactionId))
                .ForMember(s => s.Milage, o => o.MapFrom(d => d.Milage))
                .ForMember(s => s.Fill, o => o.MapFrom(d => d.Fill))
                .ForMember(s => s.Oil, o => o.MapFrom(d => d.Oil))
                .ForMember(s => s.Fuel, o => o.MapFrom(d => d.Fuel))
                .ForMember(s => s.Service, o => o.MapFrom(d => d.Service))
                .ForMember(s => s.VehicleId, o => o.MapFrom(d => d.VehicleId))
                .ForMember(s => s.Dirty, o => o.Ignore());

            CreateMap<VehicleTransaction, Business.Entities.VehicleTransaction>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.TransactionId, o => o.MapFrom(d => d.TransactionId))
                .ForMember(s => s.Milage, o => o.MapFrom(d => d.Milage))
                .ForMember(s => s.Fill, o => o.MapFrom(d => d.Fill))
                .ForMember(s => s.Oil, o => o.MapFrom(d => d.Oil))
                .ForMember(s => s.Service, o => o.MapFrom(d => d.Service))
                .ForMember(s => s.VehicleId, o => o.MapFrom(d => d.VehicleId));

            CreateMap<Business.Entities.AccountMonthlyTotal, AccountMonthlyTotal>()
                .ForMember(s => s.Month, o => o.MapFrom(d => d.Month))
                .ForMember(s => s.MonthlyTotal, o => o.MapFrom(d => d.MonthlyTotal))
                .ForMember(s => s.CumulativeTotal, o => o.MapFrom(d => d.CumulativeTotal))
                .ForMember(s => s.Dirty, o => o.Ignore());

            CreateMap<AccountMonthlyTotal, Business.Entities.AccountMonthlyTotal>()
                .ForMember(s => s.Month, o => o.MapFrom(d => d.Month))
                .ForMember(s => s.MonthlyTotal, o => o.MapFrom(d => d.MonthlyTotal))
                .ForMember(s => s.CumulativeTotal, o => o.MapFrom(d => d.CumulativeTotal));

            CreateMap<SummaryReport, Business.Entities.SummaryReport>()
                .ForMember(s => s.Expanse, o => o.MapFrom(d => d.Expanse))
                .ForMember(s => s.Income, o => o.MapFrom(d => d.Income))
                .ForMember(s => s.TotalWorth, o => o.MapFrom(d => d.TotalWorth))
                .ForMember(s => s.ExpectedSaving, o => o.MapFrom(d => d.ExpectedSaving))
                .ForMember(s => s.PercentIncomeChange, o => o.MapFrom(d => d.PercentIncomeChange))
                .ForMember(s => s.PercentExpanseChange, o => o.MapFrom(d => d.PercentExpanseChange));
            CreateMap<Business.Entities.SummaryReport, SummaryReport>()
                .ForMember(s => s.Expanse, o => o.MapFrom(d => d.Expanse))
                .ForMember(s => s.Income, o => o.MapFrom(d => d.Income))
                .ForMember(s => s.TotalWorth, o => o.MapFrom(d => d.TotalWorth))
                .ForMember(s => s.ExpectedSaving, o => o.MapFrom(d => d.ExpectedSaving))
                .ForMember(s => s.PercentIncomeChange, o => o.MapFrom(d => d.PercentIncomeChange))
                .ForMember(s => s.PercentExpanseChange, o => o.MapFrom(d => d.PercentExpanseChange))
                .ForMember(s => s.Dirty, o => o.Ignore());

            CreateMap<Business.Entities.Target, Target>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Amount, o => o.MapFrom(d => d.Amount))
                .ForMember(s => s.TagId, o => o.MapFrom(d => d.TagId))
                .ForMember(s => s.TargetDate, o => o.MapFrom(d => d.TargetDate))
                .ForMember(s => s.TargetType, o => o.MapFrom(d => d.TargetType))
                .ForMember(s => s.Title, o => o.MapFrom(d => d.Title))
                .ForMember(s => s.AccountId, o => o.MapFrom(d => d.AccountId))
                .ForMember(s => s.Dirty, o => o.Ignore());
            CreateMap<Target, Business.Entities.Target>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Amount, o => o.MapFrom(d => d.Amount))
                .ForMember(s => s.TagId, o => o.MapFrom(d => d.TagId))
                .ForMember(s => s.TargetDate, o => o.MapFrom(d => d.TargetDate))
                .ForMember(s => s.TargetType, o => o.MapFrom(d => d.TargetType))
                .ForMember(s => s.Title, o => o.MapFrom(d => d.Title))
                .ForMember(s => s.AccountId, o => o.MapFrom(d => d.AccountId));

            CreateMap<Business.Entities.Bill, Bill>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Amount, o => o.MapFrom(d => d.Amount))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.DueDate, o => o.MapFrom(d => d.DueDate))
                .ForMember(s => s.ExpiryDate, o => o.MapFrom(d => d.ExpiryDate))
                .ForMember(s => s.Paid, o => o.MapFrom(d => d.Paid.Value))
                .ForMember(s => s.Recurring, o => o.MapFrom(d => d.Recurring.Value))
                .ForMember(s => s.RecurringFequency, o => o.MapFrom(d => (RecurringFrequencyTypes)d.RecurringFequency))
                .ForMember(s => s.Dirty, o => o.Ignore())
                .ForMember(s => s.Error, o => o.Ignore());

            CreateMap<Bill, Business.Entities.Bill>()
                .ForMember(s => s.Id, o => o.MapFrom(d => d.Id))
                .ForMember(s => s.Amount, o => o.MapFrom(d => d.Amount))
                .ForMember(s => s.Name, o => o.MapFrom(d => d.Name))
                .ForMember(s => s.DueDate, o => o.MapFrom(d => d.DueDate))
                .ForMember(s => s.ExpiryDate, o => o.MapFrom(d => d.ExpiryDate))
                .ForMember(s => s.Paid, o => o.MapFrom(d => d.Paid))
                .ForMember(s => s.Recurring, o => o.MapFrom(d => d.Recurring))
                .ForMember(s => s.RecurringFequency, o => o.MapFrom(d => (int)d.RecurringFequency));

            Mapper.AssertConfigurationIsValid();
        }
    }
}